﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DGIS.Map.Templetes
{
    /// <summary>
    /// MenuItem.xaml 的交互逻辑
    /// </summary>
    public partial class MenuItem : UserControl,INotifyPropertyChanged
    {
        public MenuItem()
        {
            InitializeComponent();

            this.MouseEnter += MenuItem_MouseEnter;
            this.MouseLeave += MenuItem_MouseLeave;
        }

        void MenuItem_MouseEnter(object sender, MouseEventArgs e)
        {
            if (!Selected)
            {
                DoubleAnimation dbAnimation = new DoubleAnimation();
                dbAnimation.From = 0;
                dbAnimation.To = 1;
                dbAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(300));
                dbAnimation.FillBehavior = FillBehavior.Stop;
                this.HightlightRect.BeginAnimation(OpacityProperty, dbAnimation);

                this.HightlightRect.Opacity = 1;
            }
        }

        void MenuItem_MouseLeave(object sender, MouseEventArgs e)
        {   
            if (!Selected)
            {
                DoubleAnimation dbAnimation = new DoubleAnimation();
                dbAnimation.From = 1;
                dbAnimation.To = 0;
                dbAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(300));
                dbAnimation.FillBehavior = FillBehavior.Stop;

                this.HightlightRect.BeginAnimation(OpacityProperty, dbAnimation);

                this.HightlightRect.Opacity = 0;
            }
            

        }

        public event PropertyChangedEventHandler PropertyChanged;

        public string MenuTitle
        {
            get { return (string)GetValue(MenuTitleProperty); }
            set { SetValue(MenuTitleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MenuTitle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MenuTitleProperty =
            DependencyProperty.Register("MenuTitle", typeof(string), typeof(MenuItem), new PropertyMetadata(""));



        public ImageSource MenuIco
        {
            get { return (ImageSource)GetValue(MenuIcoProperty); }
            set { SetValue(MenuIcoProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MenuIco.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MenuIcoProperty =
            DependencyProperty.Register("MenuIco", typeof(ImageSource), typeof(MenuItem), new PropertyMetadata(null));



        public double BackgroundOpacity
        {
            get{return (double)GetValue(BackgroundOpacityProperty);}
            set{SetValue(BackgroundOpacityProperty, value);}
        }

        // Using a DependencyProperty as the backing store for BackgroundOpacity.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BackgroundOpacityProperty =
            DependencyProperty.Register("BackgroundOpacity", typeof(double), typeof(MenuItem), new PropertyMetadata(0.00));



        public bool Selected
        {
            get { return (bool)GetValue(SelectedProperty); }
            set
            {
                SetValue(SelectedProperty, value);

                this.ProgressPropertyChanged("Selected");
                this.HightlightRect.Opacity = Selected ? 1 : 0;
            }
        }

        // Using a DependencyProperty as the backing store for Selected.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SelectedProperty =
            DependencyProperty.Register("Selected", typeof(bool), typeof(MenuItem), new PropertyMetadata(false));

        private void ProgressPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }
}
